package com.siyu.tickets.action;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.siyu.core.manager.SysUserMng;
import com.siyu.tickets.entity.SysUser;
import com.siyu.tickets.manager.PartnerMng;
import com.siyu.tickets.manager.SupplierMng;
import com.siyu.tickets.web.SysUtils;

/**
 * 管理员欢迎页面
 * 
 * @since 2013-7-10
 * @version 0.1
 * @author cuigx
 */
@Controller
public class WelcomeAdminAct {

	@RequestMapping("/")
	public String welcome() {
		return "redirect:admin";
	}

	@RequestMapping("/admin")
	public String index() {
		return "admin/index";
	}

	@RequestMapping("/admin_top")
	public String top(HttpServletRequest request, ModelMap model) {
		SysUser user = SysUtils.getUser(request);
		model.addAttribute("user", user);
		return "admin/top";
	}

	@RequestMapping("/admin_main")
	public String main() {
		return "admin/main";
	}

	@RequestMapping("/admin_left")
	public String left() {
		return "admin/left";
	}

	@RequestMapping("/admin_right")
	public String right() {
		return "admin/right";
	}

	@RequestMapping(value = "/admin_setting", method = RequestMethod.GET)
	public String setting(HttpServletRequest request, ModelMap model) {
		return "admin/setting";
	}

	@RequestMapping(value = "/admin_setting", method = RequestMethod.POST)
	public String settingSubmit(String password, String email, HttpServletRequest request, ModelMap model) {
		model.addAttribute("message", "操作成功");

		SysUser user = SysUtils.getUser(request);
		// 修改密码
		userMng.update(user.getId(), password, email);

		if (SysUser.USER_TYPE.PARTNER.equals(user.getUserType())) {
			// TODO
		} else if (SysUser.USER_TYPE.ADMIN.equals(user.getUserType())) {
			// TODO
		} else if (SysUser.USER_TYPE.ADMIN.equals(user.getUserType())) {
			// TODO
		} else {
			model.addAttribute("message", "无效的用户类型");
		}
		return setting(request, model);
	}

	@Autowired
	private SysUserMng userMng;

	@Autowired
	private PartnerMng partnerMng;

	@Autowired
	private SupplierMng supplierMng;

}
